<?php
namespace App\Http\Controllers\ApiAdmin;

use App\Service\Admin\TiebaService;
use Illuminate\Http\Request;

class TiebaController extends BaseController
{
    //用户

    public function __construct(TiebaService $service)
    {
        $this->db = $service;
    }

    //列表
    public function getIndex(Request $request)
    {
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('limit', 10);
        $res = $this->db->getList($pages);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }

    //详情
    public function getOne(Request $request)
    {
        $id = $request->post('id', 0);
        $res = $this->db->getOne($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data']);
    }

    //回复列表
    public function replyList(Request $request)
    {
        $pages['start'] = $request->post('page', 1);
        $pages['limit'] = $request->post('limit', 10);
        $id = $request->post('id', 0);
        $res = $this->db->getReplyList($id);
        if ($res['code'] < 0) {
            return $this->toJson(-2, $res['msg']);
        }
        return $this->toJson(0, '', $res['data'], $res['total']);
    }
}